﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.Common;
using Fasterflect;

namespace ShahyadS.BuildInspectorVSPackage
{
	public static class VsTeamExplorerExtensions
	{
		public static BaseHierarchyNode GetRootNode(this IVsTeamExplorer vsTeamExporer)
		{
			return vsTeamExporer.TeamExplorerUIHierarchy.GetPropertyValue("ServerNode") as BaseHierarchyNode;
		}
		public static BaseHierarchyNode GetTeamProjectNode(this IVsTeamExplorer vsTeamExporer, String TeamProject)
		{
			var root = vsTeamExporer.GetRootNode();
			var child = root.FirstChild;
			while (child != null)
			{
				if (child.GetType().Name == "ProjectNode" && child.Name == TeamProject)
					return child;
				child = child.NextSibling;
			}
			return child;
		}
		public static List<BaseHierarchyNode> GetTeamProjectNodes(this IVsTeamExplorer vsTeamExporer)
		{
			List<BaseHierarchyNode> teamProjectNodes = new List<BaseHierarchyNode>();
			var root = vsTeamExporer.GetRootNode();
			var child = root.FirstChild;
			while (child != null)
			{
				if (child.GetType().Name == "ProjectNode")
					teamProjectNodes.Add(child);
				child = child.NextSibling;
			}
			return teamProjectNodes;
		}

	}
}
